import 'package:get/get.dart';
import 'package:hygf/http/file_transfer/down_cap.dart';

import '../../../../http/DioClient.dart';
import '../../../../view/image_picker_widget.dart';
import 'state.dart';

class BaseMsgLogic extends GetxController {
  final BaseMsgState state = BaseMsgState();

  @override
  void onReady() {
    super.onReady();
    initImgUrl();
  }

  Future<void> initImgUrl() async {
    if ((state.itemData.idNumberPositive ?? "").isNotEmpty) {
      List<ImagePickerData> idNumberPositiveData =
      await DioClient().requestImgUrl(state.itemData.idNumberPositive);
      state.idController.addImages(idNumberPositiveData);
    }
    if ((state.itemData.idNumberNegative ?? "").isNotEmpty) {
      List<ImagePickerData> idNumberNegativeData =
      await DioClient().requestImgUrl(state.itemData.idNumberNegative);
      state.idBackController.addImages(idNumberNegativeData);
    }
    if ((state.itemData.bankCardPhoto ?? "").isNotEmpty) {
      List<ImagePickerData> bankCardData =
          await DioClient().requestImgUrl(state.itemData.bankCardPhoto);
      state.bankImageController.addImages(bankCardData);
    }
    if ((state.itemData.houseTitleCertificate ?? "").isNotEmpty) {
      List<ImagePickerData> houseData =
          await DioClient().requestImgUrl(state.itemData.houseTitleCertificate);
      state.houseImageController.addImages(houseData);
    }
    if ((state.itemData.gatePhoto ?? "").isNotEmpty) {
      List<ImagePickerData> gateData =
          await DioClient().requestImgUrl(state.itemData.gatePhoto);
      state.gateImageController.addImages(gateData);
    }
    if ((state.itemData.other ?? "").isNotEmpty) {
      List<ImagePickerData> otherData =
          await DioClient().requestImgUrl(state.itemData.other);
      state.otherImageController.addImages(otherData);
    }
    update();
  }
}
